package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.MesSaleOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * created by wangjunfu on 2022-03-30 15:35:11
 */
@Repository
public class MesSaleOrderDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(MesSaleOrderDao.class);

    public MesSaleOrder insert(final MesSaleOrder mesSaleOrder) {
        insert("MesSaleOrder.insert", mesSaleOrder);
        return mesSaleOrder;
    }

    public Boolean updateInfoById(final MesSaleOrder mesSaleOrder) {
        return update("MesSaleOrder.updateInfoById", mesSaleOrder) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("MesSaleOrder.updateInfoByQuery", query) > 0;
    }

    public MesSaleOrder selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("MesSaleOrder.selectById", query);
    }

    public List<MesSaleOrder> selectByQuery(final Query query) {
        return queryForList("MesSaleOrder.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("MesSaleOrder.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        MesSaleOrder mesSaleOrder = new MesSaleOrder();
        mesSaleOrder.setDeleteFlag(1);
        mesSaleOrder.setId(id);
        mesSaleOrder.setEntId(entId);

        return update("MesSaleOrder.updateInfoById", mesSaleOrder) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("MesSaleOrder.deleteById", query) > 0;
    }

    //以map的形式返回数据
    public List<Map<String, String>> getMapDataByQuery(final Query query, final String element) {
        return queryForList("MesSaleOrder." + element, query);
    }
}